/* Aarons MP3 Player
Quick fix since the switch to WebKit dosent work with windowless players (Like windows media)
Also still working on getting MMS and other radio streams to work with flash based players.
So this is just temp untill i get streams working, the new radio is gonna be using the PlayX libs.
So im hoping to include a clientside PlayX with it, so you can watch youtube videos without others.
*/
local aaronsmenuversion = "Aaron's MP3 Player"
local aaronsmenushortversion = "A-Play"
local firstruncheck = 0
local pan
local function showPanel()
	if firstruncheck == 0 then
		panel = vgui.Create( "DFrame" )
		panel:SetPos( 100, 60)
		panel:SetSize(800, 600)
		panel:SetTitle( aaronsmenuversion )
		panel:SetVisible( true )
		panel:SetDraggable( true )
		panel:ShowCloseButton( false )
		panel:SetSizable(true)
		panel:MakePopup()
		pan = panel
		local w = panel:GetWide()
		local h =  panel:GetTall()
		local closebutton = vgui.Create( "DImageButton", panel ) 
		closebutton:SetPos( 780, 5 )
		closebutton:SetImage( "silkicons/cross.vtf" )
		closebutton:SizeToContents()
		closebutton.DoClick = function()
			LocalPlayer():ConCommand("-aaronsmenu")
		end
		local PropertySheet = vgui.Create( "DPropertySheet" )
		PropertySheet:SetParent( panel )
		PropertySheet:SetPos( 5, 30 )
		PropertySheet:SetSize( w-10, h-35 ) 
		--------------------------Begin Radio Tab----------------------------------
		radiourl = [[<html>
					<body><font size="1" face="Verdana"><center>
					<b>Welcome</b><br>
					You can load your custom mp3 url's by pressing the "load custom mp3" button below <br>
					Make sure you dont put the http:// tho or else it wont work<br>
					Or you can load one of our fine selection of mp3s above :D <br>
					<font size="1" face="Verdana"></center>
					</body>
					</html>
					]]
		local RADIO = vgui.Create( "DPanel", PropertySheet )
		RADIO:SetSize( w-20, h-45 )
		radiolist = vgui.Create("DListView")
		radiolist:SetParent(RADIO)
		radiolist:SetPos(1, 1)
		radiolist:SetSize(775, 430)
		radiolist:SetMultiSelect(false)
		radiolist:SetSortable(true)
		local lstRadioTitle = radiolist:AddColumn("Title")
		local lstRadioURL = radiolist:AddColumn("URL")
		local lstRadioGenre = radiolist:AddColumn("Genre")
		local lstRadioType = radiolist:AddColumn("Type")
		radiolist:SortByColumn( 1 )
		lstRadioTitle:SetWide( 100 )
		lstRadioURL:SetWide( 300 )
		lstRadioGenre:SetWide( 15 )
		lstRadioType:SetWide( 1 )
		radiopage = vgui.Create( "HTML" , RADIO)
		radiopage:SetPos( 0, 445)
		radiopage:SetSize( 775, 255 )
		radiopage:SetVisible( true )
		radiopage:SetHTML( radiourl )
		radiolist.OnRowSelected = function()
			radioselect = DermaMenu()
			radioselect:AddOption("Load This", function()
				panel:SetTitle( aaronsmenushortversion.." - Currently Listining To: Title: "..radiosongTitle..
				"  URL: "..radiosongURL.."  Genre: "..radiosongGenre )
				radiourl = [[<embed src="http://www.google.com/reader/ui/3523697345-audio-player.swf"
							flashvars="audioUrl=http://]]..radiosongURL..[[&autoPlay=true" width="750" height="27" 
							pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>]]
				radiopage:SetHTML( radiourl );
				print("\n\nCurrently Selected Song: \nTitle: "..radiosongTitle.."\nURL: "..radiosongURL.."\nGenre: "
				..radiosongGenre.."\nType: "..radiosongType.."\n\n")
			end )
			radioselect:Open()
		radiosongTitle = radiolist:GetLine(radiolist:GetSelectedLine()):GetValue(1)
		radiosongURL = radiolist:GetLine(radiolist:GetSelectedLine()):GetValue(2)
		radiosongGenre = radiolist:GetLine(radiolist:GetSelectedLine()):GetValue(3)
		radiosongType = radiolist:GetLine(radiolist:GetSelectedLine()):GetValue(4)
		end
		radiostop = vgui.Create( "DButton", RADIO )
		radiostop:SetParent( RADIO )
		radiostop:SetSize( RADIO:GetWide()-500, 15 )
		radiostop:SetPos( 490, 432 )
		radiostop:SetText( "Refresh The List" )
		radiostop.DoClick = function( button )
			LocalPlayer():ConCommand( "aaronsmenu_reload" )
		end
		radiostop = vgui.Create( "DButton", RADIO )
		radiostop:SetParent( RADIO )
		radiostop:SetSize( RADIO:GetWide()-532, 15 )
		radiostop:SetPos( 248,432 )
		radiostop:SetText( "Turn Off The Player" )
		radiostop.DoClick = function( button )
			radiourl = [[<center>Radio Stopped</center>]]
			radiopage:SetHTML( radiourl );
			panel:SetTitle( aaronsmenuversion )
		end
		radioload = vgui.Create( "DButton", RADIO )
		radioload:SetParent( RADIO )
		radioload:SetSize( RADIO:GetWide()-532, 15 )
		radioload:SetPos( 1,432 )
		radioload:SetText( "Load Custom MP3" )
		radioload.DoClick = function( button )
			local customradio = vgui.Create( "DFrame" )
			customradio:SetPos( 250,250 )
			customradio:SetSize( 500, 50 )
			customradio:SetTitle( "MP3 Link: (dont put the http://)" )
			customradio:ShowCloseButton( true )
			customradio:SetVisible( true )
			customradio:MakePopup()
			local customradiotext = vgui.Create( "DTextEntry", customradio )
			customradiotext:SetPos( 20,27 )
			customradiotext:SetTall( 20 )
			customradiotext:SetWide( 450 )
			customradiotext:SetEnterAllowed( true )
			customradiotext.OnEnter = function()
				customradiourl = customradiotext:GetValue()
				radiourl = [[<embed src="http://www.google.com/reader/ui/3523697345-audio-player.swf"
							flashvars="audioUrl=http://]]..customradiourl..[[&autoPlay=true" width="750" height="27" 
							pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>]]
				radiopage:SetHTML( radiourl );
				panel:SetTitle( aaronsmenushortversion.." - Currently Listining To: "..customradiourl)
				customradio:SetVisible( false )
				end
			end
		function FetchList ( SiteArgs, SiteSize )
			MusicList = {};
			for _, Line in pairs(string.Explode("\n", SiteArgs)) do
			if string.len(Line) > 5 then
				Info = string.Explode("\t", Line);
				TempT = {};
				TempT.Title = Info[1];
				TempT.URL = Info[2];
				TempT.Genre = Info[3];
				TempT.Type = Info[4];
				table.insert(MusicList, TempT)
				end
			end
			for k, v in pairs(MusicList) do
				radiolist:AddLine(v.Title,v.URL,v.Genre,v.Type)
			end
		end
		
		function reloadAaronsRadio()
			radiolist:Clear()
			http.Get("http://aarons-gmodlua.googlecode.com/svn/trunk/gmradio/gmradio-mp3.txt", "", FetchList)
		end
		http.Get("http://aarons-gmodlua.googlecode.com/svn/trunk/gmradio/gmradio-mp3.txt", "", FetchList)
		concommand.Add("aaronsmenu_reload", reloadAaronsRadio)
	-----------------------End Radio Tab-----------------------
	-------------------Begin Playertab-------------------------
		local PLAYER = vgui.Create("DListView")
		PLAYER:SetParent(PLAYER)
		PLAYER:SetPos(25, 80)
		PLAYER:SetSize( PLAYER:GetWide() - 20, PLAYER:GetTall()-80 )
		PLAYER:SetMultiSelect(false)
		PLAYER:SetSortable(true)
		local lstName = PLAYER:AddColumn("Name")
		local lstAdmin = PLAYER:AddColumn("Admin?")
		local lstHP = PLAYER:AddColumn("Health")
		local lstArm = PLAYER:AddColumn("Armor")
		local lstWep = PLAYER:AddColumn("Weapon")
		local lstKils = PLAYER:AddColumn("Frags")
		local lstAlv = PLAYER:AddColumn("Alive?")
		local lstVeh = PLAYER:AddColumn("In Vehicle?")
		local lstDis = PLAYER:AddColumn("Distance")
		PLAYER:SortByColumn( 6 )
		lstName:SetWide( 200 )
		lstAdmin:SetWide( 5 )
		lstHP:SetWide( 2 )
		lstArm:SetWide( 2 )
		lstWep:SetWide( 150 )
		lstKils:SetWide( 5 )
		lstAlv:SetWide( 5 )
		lstVeh:SetWide( 8 )
		lstDis:SetWide( 5 )
		function reloadplylist()
		PLAYER:Clear()
		for k,v in pairs(player.GetAll()) do
			plypos = v:GetPos()
			if v:GetActiveWeapon():IsValid() then plyweap = v:GetActiveWeapon():GetPrintName() else plyweap = "N/A - Dead/Stripped/Ragdolled" end
			PLAYER:AddLine(v:Nick(),v:IsAdmin(),v:Health(),v:Armor(),plyweap,v:Frags(),v:Alive(),
			v:InVehicle(),tostring(math.floor(plypos:Distance(LocalPlayer():GetPos()))))
			PLAYER.OnRowSelected = function()
				local PLAYERULX = DermaMenu()
				PLAYERULX:AddOption("SSlay", function()
					LocalPlayer():ConCommand("ulx sslay \""..targetply.."\""); end )
				PLAYERULX:AddOption("Rocket", function()
					LocalPlayer():ConCommand("ulx rocket \""..targetply.."\""); end )
				PLAYERULX:AddOption("Explode", function()
					LocalPlayer():ConCommand("ulx explode \""..targetply.."\"9999 250"); end )
				PLAYERULX:AddOption("Whip", function()
					local cexpanel = vgui.Create( "DFrame" )
					cexpanel:SetPos( 250,250 )
					cexpanel:SetSize( 500, 50 )
					cexpanel:SetTitle( "Whip "..targetply.." For X times With X Damage" )
					cexpanel:ShowCloseButton( true )
					cexpanel:SetVisible( true )
					cexpanel:MakePopup()
					local cextext = vgui.Create( "DTextEntry", cexpanel )
					cextext:SetPos( 20,27 )
					cextext:SetTall( 20 )
					cextext:SetWide( 450 )
					cextext:SetEnterAllowed( true )
					cextext.OnEnter = function()
						cexargs = cextext:GetValue()
						cexpanel:SetVisible( false )
						LocalPlayer():ConCommand("ulx whip \""..targetply.."\" "..cexargs);
						end
					end )
				PLAYERULX:AddOption("Kick", function()
					local kickpanel = vgui.Create( "DFrame" )
					kickpanel:SetPos( 250,250 )
					kickpanel:SetSize( 500, 50 )
					kickpanel:SetTitle( "Kick Reason For: "..targetply )
					kickpanel:ShowCloseButton( true )
					kickpanel:SetVisible( true )
					kickpanel:MakePopup()
					local kicktext = vgui.Create( "DTextEntry", kickpanel )
					kicktext:SetPos( 20,27 )
					kicktext:SetTall( 20 )
					kicktext:SetWide( 450 )
					kicktext:SetEnterAllowed( true )
					kicktext.OnEnter = function()
						kickreason = kicktext:GetValue()
						kickpanel:SetVisible( false )
						LocalPlayer():ConCommand("ulx kick \""..targetply.."\" \""..kickreason.."\"");
						end
					end )
				PLAYERULX:AddOption("Ban", function()
					local banpanel = vgui.Create( "DFrame" )
					banpanel:SetPos( 250,250 )
					banpanel:SetSize( 500, 50 )
					banpanel:SetTitle( "Ban Time For: "..targetply )
					banpanel:ShowCloseButton( true )
					banpanel:SetVisible( true )
					banpanel:MakePopup()
					local bantext = vgui.Create( "DTextEntry", banpanel )
					bantext:SetPos( 20,27 )
					bantext:SetTall( 20 )
					bantext:SetWide( 450 )
					bantext:SetEnterAllowed( true )
					bantext.OnEnter = function()
						bantime = bantext:GetValue()
						banpanel:SetVisible( false )
						local banpanel2 = vgui.Create( "DFrame" )
						banpanel2:SetPos( 280,280 )
						banpanel2:SetSize( 500, 50 )
						banpanel2:SetTitle( "Ban Reason For: "..targetply )
						banpanel2:ShowCloseButton( true )
						banpanel2:SetVisible( true )
						banpanel2:MakePopup()
						local bantext2 = vgui.Create( "DTextEntry", banpanel2 )
						bantext2:SetPos( 20,27 )
						bantext2:SetTall( 20 )
						bantext2:SetWide( 450 )
						bantext2:SetEnterAllowed( true )
						bantext2.OnEnter = function()
							banreason = bantext2:GetValue()
							banpanel:SetVisible( false )
							banpanel2:SetVisible( false )
							LocalPlayer():ConCommand("ulx ban \""..targetply.."\" "..bantime.." \""..banreason.."\"");
							end
					end
				end )
				PLAYERULX:Open()
				local selected = PLAYER:GetLine(PLAYER:GetSelectedLine()):GetValue(1)
				for k,v in pairs(player.GetAll()) do
						if v:Nick() == selected then
							targetply = v:Nick()
							print("\nTarget is: ".. targetply .."\n\n")
						end
				end
			end
		end
		end
	---------------------End Player Tab---------------------

		PropertySheet:AddSheet( "Aaron's MP3 Player", RADIO, "gui/silkicons/sound", false, false, "Listen To Some Music" )
		PropertySheet:AddSheet( "Player List/Info", PLAYER, "gui/silkicons/group", false, false, "Player Stats/Info And Punishment Options For Admins" )
		reloadplylist()
		reloadAaronsRadio()
		firstruncheck = 1
	else
		gui.SetMousePos(mouseExitPosX, mouseExitPosY)
		panel:SetVisible(true)
		gui.EnableScreenClicker(true)
		reloadplylist()
	end
end
local function hidePanel()
	mouseExitPosX, mouseExitPosY = gui.MousePos()
	if panel:IsVisible() then
		panel:SetVisible(false)
	end
	gui.EnableScreenClicker(false)
end
concommand.Add("+aaronsmenu", showPanel)
concommand.Add("-aaronsmenu", hidePanel)